class Solution {
public:
    string addStrings(string num1, string num2) {
        string ret;
        int num1i = 0;
        int num2i = 0;
        int carry = 0;
        int n1 = 0;
        int n2 = 0;
        while (num1i < num1.size() || num2i < num2.size()) {
            n1 = num1i < num1.size() ? num1[num1.size() - 1 - num1i] - '0' : 0;
            n2 = num2i < num2.size() ? num2[num2.size() - 1 - num2i] - '0' : 0;

            ret += (n1 + n2 + carry) % 10 + '0';
            carry = (n1 + n2 + carry) / 10;
            num1i++;
            num2i++;
        }
        if (carry) {
            ret += '1';
        }

        reverse(ret.begin(), ret.end());
        return ret;
    }
    string multiply(string num1, string num2) {
        if (num1[0] == '0' || num2[0] == '0')
            return "0";
        string ret1, ret2;

        for (int i = 0; i < num1.size(); i++) {
            int carry = 0;
            ret2.resize(0);
            for (int n = 0; n < i; n++) {
                ret2 += '0';
                continue;
            }
            for (int j = 0; j < num2.size(); j++) {
                ret2 += ((num2[num2.size() - 1 - j] - '0') *
                    (num1[num1.size() - 1 - i] - '0') +
                    carry) %
                    10 +
                    '0';
                carry = ((num2[num2.size() - 1 - j] - '0') *
                    (num1[num1.size() - 1 - i] - '0') +
                    carry) /
                    10;
            }
            if (carry)
                ret2 += carry + '0';
            reverse(ret2.begin(), ret2.end());
            ret1 = addStrings(ret1, ret2);
        }
        // for (int i = 0; i < ret1.size() - 1; i++) {
        //     if ('0' == ret1[0]) {
        //         ret1.erase(0, 1);
        //         i--;
        //     }
        // }
        return ret1;
    }
};